package han.controller;


import han.pojo.Details;
import han.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @authou HanDianWei
 * @create 2020-10-23 15:04
 */
@Controller
@RequestMapping("/detail")
public class DetailController {
    @Autowired
    @Qualifier("DetailService")
    private DetailService detailService;

//   查询全部的垃圾，并返回到一个展示界面
    @RequestMapping("/rsDetail")
    public String list(Model model){
        List<Details> details=detailService.getAllDetail();
        model.addAttribute("list",details);
        return "tourists/rsDetail";
    }
    @RequestMapping("/allDetail")
    public String list1(Model model){
        List<Details> details=detailService.getAllDetail();
        model.addAttribute("list",details);
        return "admin/allDetail";
    }

//     跳转到增加垃圾页面
    @RequestMapping("/toAddDetail")
    public String toAddPaper(){
        return "admin/addDetail";
    }

//    添加垃圾的请求
    @RequestMapping("/addDetail")
    public String addDetail(Details details){
        detailService.addDetail(details);
        return "redirect:/detail/allDetail";  //重定向到/detail/allDetail的请求

    }
//    跳转到修改页面
    @RequestMapping("/toUpdate")
    public String toUpdDetail(int id,Model model){
        Details details = detailService.getDetailById(id);
        model.addAttribute("QDetail",details);
        return "admin/updDetail";
    }
//    修改垃圾
    @RequestMapping("/updDetail")
    public String updDetail(Details details){
        detailService.updDetail(details);
        return "redirect:/detail/allDetail";
    }

//   删除  不需要跳转新的页面
    @RequestMapping("/delDetail")
    public String delDetail(int d_id){
        detailService.delDetailById(d_id);
        return "redirect:/detail/allDetail";
    }
//    查询一个垃圾
    @RequestMapping("/queryDetail")
    public String getDetailByName(String getDetailByName,Model model){
        List<Details> detailsList = detailService.getDetailByName(getDetailByName);
        if(detailsList==null){
           model.addAttribute("error","未找到该垃圾，请换一个吧");
        }
        model.addAttribute("list",detailsList);
        return "tourists/rsDetail";
    }
    @RequestMapping("/queryDetails")
    public String getDetailByName1(String getDetailByName,Model model){
        List<Details> detailsList = detailService.getDetailByName(getDetailByName);
        if(detailsList==null){
            model.addAttribute("error","未找到该垃圾，请换一个吧");
        }
        model.addAttribute("list",detailsList);
        return "admin/allDetail";
    }

    @RequestMapping("/gDetail")
    public String getDetailByClassId(Model model){
        List<Details> detailByClassId = detailService.getDetailByClassId(1);
        model.addAttribute("list",detailByClassId);
        return "tourists/rsDetail";
    }


    @RequestMapping("/sDetail")
    public String getDetailByClassId2(Model model){
        List<Details> detailByClassId = detailService.getDetailByClassId(2);
        model.addAttribute("list",detailByClassId);
        return "tourists/rsDetail";
    }

    @RequestMapping("/khsDetail")
    public String getDetailByClassId3(Model model){
        List<Details> detailByClassId = detailService.getDetailByClassId(3);
        model.addAttribute("list",detailByClassId);
        return "tourists/rsDetail";
    }
    @RequestMapping("/yhDetail")
    public String getDetailByClassId4(Model model){
        List<Details> detailByClassId = detailService.getDetailByClassId(4);
        model.addAttribute("list",detailByClassId);
        return "tourists/rsDetail";
    }






}
